package com.nand.module.function.ui;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.huantansheng.easyphotos.EasyPhotos;
import com.huantansheng.easyphotos.callback.SelectCallback;
import com.huantansheng.easyphotos.models.album.entity.Photo;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.interfaces.OnSelectListener;
import com.lzy.okgo.model.HttpParams;
import com.nand.library.base.base.BaseActivity;
import com.nand.library.base.bean.ResponseBean;
import com.nand.library.base.http.MyCallback;
import com.nand.library.base.http.OkGoUtils;
import com.nand.library.base.utils.GlideEngine;
import com.nand.library.base.utils.ObjectUtils;
import com.nand.library.base.utils.SpUtils;
import com.nand.module.function.R;
import com.nand.module.function.adapter.SpAdapter;
import com.nand.module.function.bean.EqDetailInfoBean;
import com.nand.module.function.bean.GradeBean;
import com.nand.module.function.bean.IdBean;
import com.nand.module.function.bean.MmhitchListBean;
import com.nand.module.function.bean.SpareParBean;
import com.nand.module.function.bean.SparePartBean;
import com.nand.module.function.constant.URL;
import com.nand.module.function.utils.LogUtils;
import com.nand.module.function.utils.ToolUtils;
import com.nand.module.function.view.ImageActivity;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.test.espresso.core.internal.deps.guava.base.Joiner;

public class NewRepairActivity extends BaseActivity implements View.OnClickListener {


    private TextView mTvGzlb, mTvGzmc, mTvGzdj, mTvWxr, mTvClff, mTvGzms;
    private TextView mTvSbbm, mTvSbmc, mTvSybm, mTvGys, mTvGysdh;
    private EditText mEtGzms, mEtWxfy, mEtClff;


    private RecyclerView mRecycler;
    private ArrayList<String> imgPathList = new ArrayList<>();
    private PublishImgAdapter imgAdapter;
    private HttpParams tjParams;
    private String eqID;
    private String oid;
    private int userId;
    private int type;

    private HttpParams params11;
    private List<String> imgList;
    private ShowImgAdapter imgAdapter2;
    private ArrayList mData;
    private ArrayList<File> files;
    private List<String> imagePath;
    private String join = "";
    private String data;
    private TextView mTvBj;
    private View mViewLine;
    private LinearLayout mLlBj;
    private RecyclerView mRvBj;
    private SpAdapter mSpAdapter;

    @Override
    protected int initLayout() {
        return R.layout.activity_new_repair;
    }

    @Override
    protected void initView() {
        userId = SpUtils.readInt(NewRepairActivity.this, "userId", 0);
        eqID = getIntent().getStringExtra("eqID");
        //0.未生效点击 1.新增
        type = getIntent().getIntExtra("type", 1);

        mTvSbbm = findViewById(R.id.tv_sbbm);
        mTvSbmc = findViewById(R.id.tv_sbmc);
        mTvSybm = findViewById(R.id.tv_sybm);
        mTvGys = findViewById(R.id.tv_gys);
        mTvGysdh = findViewById(R.id.tv_gysdh);
        mEtGzms = findViewById(R.id.et_gzms);
        mEtWxfy = findViewById(R.id.et_wxfy);
        mEtWxfy.addTextChangedListener(money);// 监听金额输入框
        mEtClff = findViewById(R.id.et_clff);
        findViewById(R.id.ll_gzlb).setOnClickListener(this);
        findViewById(R.id.ll_gzmc).setOnClickListener(this);
        findViewById(R.id.ll_gzdj).setOnClickListener(this);
        findViewById(R.id.ll_wxr).setOnClickListener(this);
        mTvWxr = findViewById(R.id.tv_wxr);
        mTvGzlb = findViewById(R.id.tv_gzlb);
        mTvGzmc = findViewById(R.id.tv_gzmc);
        mTvGzdj = findViewById(R.id.tv_gzdj);
        mTvGzms = findViewById(R.id.tv_gzms);
        mTvClff = findViewById(R.id.tv_clff);

        //备件部分
        mLlBj = findViewById(R.id.ll_bj);
        mViewLine = findViewById(R.id.view_line);
        mTvBj = findViewById(R.id.tv_bj);
        mRvBj = findViewById(R.id.recycler_bj);

        imagePath = new ArrayList();

        findViewById(R.id.tv_repair_confirm).setOnClickListener(this);
        mRecycler = findViewById(R.id.recycler);


        params11 = new HttpParams();
        switch (type) {
            case 0: //0.未生效点击 1.新增
                mEtClff.setVisibility(View.GONE);
                mEtGzms.setVisibility(View.GONE);
                mLlBj.setVisibility(View.VISIBLE);
                mViewLine.setVisibility(View.VISIBLE);
                mRvBj.setVisibility(View.VISIBLE);
                mLlBj.setOnClickListener(this);
                mRecycler.setLayoutManager(new LinearLayoutManager(this));
                GridLayoutManager layoutManager2 = new GridLayoutManager(this, 3);
                mRecycler.setLayoutManager(layoutManager2);
                imgAdapter2 = new ShowImgAdapter(this);
                mRecycler.setAdapter(imgAdapter2);
                imgAdapter2.setImgItemClickListener(new ShowImgAdapter.ImgItemClick() {
                    @Override
                    public void itemClick(String url, int position) {
                        Intent intent1 = new Intent(mContext, ImageActivity.class);
                        intent1.putStringArrayListExtra(ImageActivity.IMG_LIST, mData);
                        startActivity(intent1);
                    }

                    @Override
                    public void lastItemClick() {

                    }

                    @Override
                    public void delImg(String url) {

                    }
                });

                params11.put("reId", eqID);
                OkGoUtils.getInstance().post(this, URL.EQREPAIR_DETAILS, params11, 1, false, callback);
                OkGoUtils.getInstance().post(this, URL.EQREPAIR_LEDGER, null, 7, false, callback);

                spPicker = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
                    @Override
                    public void onOptionsSelect(int options1, int options2, int options3, View v) {

                        mTvBj.setText("继续添加");

                        for (int i = 0; i < mListNewBj.size(); i++) {
                            if (mListBj.get(options1).equals(mListNewBj.get(i).getSpName())){
                                showToast(mListBj.get(options1)+"备件已添加，请选择其他备件");
                                return;
                            }

                        }
                        mListNewBj.add(mListRawBj.get(options1));
                        mSpAdapter.setData(mListNewBj);
                    }
                }).setSubmitText("确定")//确定按钮文字
                        .setCancelText("取消")//取消按钮文字
                        .setSubCalSize(14)//确定和取消文字大小
                        .setSubmitColor(Color.GRAY)//确定按钮文字颜色
                        .setCancelColor(Color.GRAY)//取消按钮文字颜色
                        .setContentTextSize(18)//滚轮文字大小
                        .setCyclic(false, false, false)//循环与否
                        .build();

                mRvBj.setLayoutManager(new LinearLayoutManager(this));
                mSpAdapter = new SpAdapter(this);

                mRvBj.setAdapter(mSpAdapter);

                mSpAdapter.setLongClickListener(new SpAdapter.OnLongClickListener() {
                    @Override
                    public boolean onLongClick(XPopup.Builder builder, final int position) {
                        builder.asAttachList(new String[]{"删除"}, null,
                                new OnSelectListener() {
                                    @Override
                                    public void onSelect(int pos, String text) {
                                        LogUtils.e("posionac==============="+position);
                                        LogUtils.e("posac==============="+pos);
                                        mListNewBj.remove(position);
                                        mSpAdapter.notifyItemRemoved(position);
                                        mSpAdapter.notifyItemRangeChanged(position,mListNewBj.size()-position);
                                      /*  adapter.remove(position);
                                        String str = adapter.getData().get(adapter.getData().size() - 1).toString();
                                        if (!add.equals(str)) {
                                            adapter.addData(adapter.getData().size(), add);
                                        }*/
                                        showToast("nihao");
                                    }
                                }).show();
                        return true;
                    }
                });

                break;
            case 1:
                mRecycler.setLayoutManager(new LinearLayoutManager(this));
                GridLayoutManager layoutManager = new GridLayoutManager(this, 3);
                mRecycler.setLayoutManager(layoutManager);
                imgAdapter = new PublishImgAdapter(this);
                imgAdapter.setImgItemClickListener(new PublishImgAdapter.ImgItemClick() {
                    @Override
                    public void itemClick(String url, int position) {
                    }

                    @Override
                    public void lastItemClick() {
                        // 添加图片
                        EasyPhotos.createAlbum(NewRepairActivity.this, true, GlideEngine.getInstance())
                                .setFileProviderAuthority("com.nand.library.base")
                                .setCount(3)
                                .start(new SelectCallback() {
                                    @Override
                                    public void onResult(final ArrayList<Photo> photos, boolean isOriginal) {
                                        for (int i = 0; i < photos.size(); i++) {
                                            files = new ArrayList<>();

                                            File file = new File(photos.get(i).path);
                                            files.add(file);

                                            final int finalI = i;
                                            OkGoUtils.getInstance().upload(NewRepairActivity.this, URL.UPLOAD_PICTURES, files, new MyCallback() {
                                                @Override
                                                public void onSuccess(ResponseBean response, int id) {
                                                    if (response.getCode() == 200) {
                                                        LogUtils.e("1ac===========" + response.getDataInfo().toString());
                                                        String s = response.getDataInfo().toString();
                                                        String substring = s.substring(2, s.length() - 2);
                                                        imgPathList.add(photos.get(finalI).path);
                                                        imagePath.add(substring);
                                                        imgAdapter.setData(imgPathList);
                                                    } else {
                                                        showToast(response.getMsg());
                                                    }
                                                }

                                                @Override
                                                public void onError(Throwable e, int id) {
                                                    showToast("上传失败");
                                                }
                                            });

                                        }
                                    }
                                });

                    }

                    @Override
                    public void delImg(String url, int position) {
                        if (imgAdapter != null) {
                            if (imgPathList.remove(url)) {
                                // 图片数量少于9张, 显示添加图片按钮
                                imgAdapter.setData(imgPathList);
                            }
                        }
                    }
                });
                mRecycler.setAdapter(imgAdapter);


                params11.put("equipID", eqID);
                OkGoUtils.getInstance().post(this, URL.GET_DETAIL_INFO, params11, 1, false, callback);
                break;
        }
    }

    // 监听金额输入框只能输入小数点后两位
    TextWatcher money = new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before,
                                  int count) {
            if (s.toString().contains(".")) {
                if (s.length() - 1 - s.toString().indexOf(".") > 2) {
                    s = s.toString().subSequence(0,
                            s.toString().indexOf(".") + 3);
                    mEtWxfy.setText(s);
                    mEtWxfy.setSelection(s.length());
                }
            }
            if (s.toString().trim().substring(0).equals(".")) {
                s = "0" + s;
                mEtWxfy.setText(s);
                mEtWxfy.setSelection(2);
            }
            if (s.toString().startsWith("0")
                    && s.toString().trim().length() > 1) {
                if (!s.toString().substring(1, 2).equals(".")) {
                    mEtWxfy.setText(s.subSequence(0, 1));
                    mEtWxfy.setSelection(1);
                }
            }
            if (s.toString().contains("..")) {
                mEtWxfy.setText("");
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    };

    @Override
    protected void initData() {
        OptionsPicker();
        OkGoUtils.getInstance().post(this, URL.MMHITCH_LIST, null, 2, false, callback);  //故障类别
        OkGoUtils.getInstance().post(this, URL.MMHITCH_GRADE_LIST, null, 3, false, callback); //故障等级
        OkGoUtils.getInstance().post(this, URL.GET_DEPART_LIST, null, 4, false, callback);  //处理人
    }

    private OptionsPickerView gzlbPicker, gzmcPicker, gzdjPicker, wxrPicker,spPicker;
    ArrayList<String> mListGzlb = new ArrayList<>();
    private String gzlbType;
    ArrayList<String> mListGzmc = new ArrayList<>();
    ArrayList<IdBean> mListRawGzmc = new ArrayList<>();
    private String gzmcType;
    private int gzmcID = 10001;
    ArrayList<String> mListGzdj = new ArrayList<>();
    ArrayList<IdBean> mListRawGzdj = new ArrayList<>();
    private int gzdjID = 10001;
    private List<String> departList = new ArrayList<>();
    private List<List<String>> staffList = new ArrayList<>();
    private List<DepartmentBean> depList = new ArrayList<>();
    private int options;
    private String departOid;
    private String userOid;
    private int wxrID = 10001;

    ArrayList<String> mListBj = new ArrayList<>();
    ArrayList<SpareParBean> mListRawBj = new ArrayList<>();
    ArrayList<SpareParBean> mListNewBj = new ArrayList<>();

    private void OptionsPicker() {
        gzlbPicker = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                gzlbType = mListGzlb.get(options1);
                mTvGzlb.setText(gzlbType);
                HttpParams params = new HttpParams();
                params.put("type", gzlbType);
                OkGoUtils.getInstance().post(NewRepairActivity.this, URL.MMHITCH_NAME, params, 5, false, callback);  //故障名称
            }
        }).setSubmitText("确定")//确定按钮文字
                .setCancelText("取消")//取消按钮文字
                .setSubCalSize(14)//确定和取消文字大小
                .setSubmitColor(Color.GRAY)//确定按钮文字颜色
                .setCancelColor(Color.GRAY)//取消按钮文字颜色
                .setContentTextSize(18)//滚轮文字大小
                .setCyclic(false, false, false)//循环与否
                .build();

        gzmcPicker = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                gzmcType = mListGzmc.get(options1);
                mTvGzmc.setText(gzmcType);
                gzmcID = mListRawGzmc.get(options1).getId();
            }
        }).setSubmitText("确定")//确定按钮文字
                .setCancelText("取消")//取消按钮文字
                .setSubCalSize(14)//确定和取消文字大小
                .setSubmitColor(Color.GRAY)//确定按钮文字颜色
                .setCancelColor(Color.GRAY)//取消按钮文字颜色
                .setContentTextSize(18)//滚轮文字大小
                .setCyclic(false, false, false)//循环与否
                .build();
        gzdjPicker = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                mTvGzdj.setText(mListGzdj.get(options1));
                gzdjID = mListRawGzdj.get(options1).getId();
            }
        }).setSubmitText("确定")//确定按钮文字
                .setCancelText("取消")//取消按钮文字
                .setSubCalSize(14)//确定和取消文字大小
                .setSubmitColor(Color.GRAY)//确定按钮文字颜色
                .setCancelColor(Color.GRAY)//取消按钮文字颜色
                .setContentTextSize(18)//滚轮文字大小
                .setCyclic(false, false, false)//循环与否
                .build();
        wxrPicker = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                //返回的分别是三个级别的选中位置
                String tx = departList.get(options1) + "/"
                        + staffList.get(options1).get(options2);

                departOid = depList.get(options1).getOid();
                userOid = depList.get(options1).getUserList().get(options2).getUserId();
                wxrID = Integer.parseInt(userOid);
                mTvWxr.setText(tx);
            }
        }).setSubmitText("确定")//确定按钮文字
                .setCancelText("取消")//取消按钮文字
                .setSubCalSize(14)//确定和取消文字大小
                .setSubmitColor(Color.GRAY)//确定按钮文字颜色
                .setCancelColor(Color.GRAY)//取消按钮文字颜色
                .setContentTextSize(18)//滚轮文字大小
                .setCyclic(false, false, false)//循环与否
                .build();
    }

    private MyCallback callback = new MyCallback() {
        @Override
        public void onSuccess(ResponseBean response, int id) {
            if (response.getCode() == 200) {
                switch (id) {
                    case 1: //页面数据
                        data = response.getDataInfo().toString();
                        LogUtils.e("data=========="+data);
                        EqDetailInfoBean bean = JSON.parseObject(data, EqDetailInfoBean.class);
                        mTvSbbm.setText(bean.getEquipId());
                        mTvSbmc.setText(bean.getEquipName());
                        mTvSybm.setText(bean.getDepartName());
                        mTvGys.setText(bean.getSupplierName());
                        mTvGysdh.setText(bean.getTelfo());

                        if (0 == type) {
                            oid = bean.getReId();
                            mTvGzms.setText(bean.getHitchDetail());
                            mEtGzms.setText(bean.getHitchDetail());
                            mTvClff.setText(bean.getDealMeth());
                            mEtClff.setText(bean.getDealMeth());
                            imgList = bean.getImgList();

                            if ("".equals(imgList) || null == imgList) {
                                return;
                            }

                            mData = new ArrayList<>();
                            for (int i = 0; i < imgList.size(); i++) {
                                mData.add(i, imgList.get(i));
                            }

                            imgAdapter2.setData(mData);
                        } else {
                            oid = bean.getOid();
                        }
                        break;
                    case 2:  //故障类别查询
                        data = response.getDataInfo().toString();
                        JSONArray jsonArray = JSONObject.parseObject(data).getJSONArray("dataList");
                        for (int i = 0; i < jsonArray.size(); i++) {
                            mListGzlb.add(jsonArray.getString(i));
                        }
                        break;
                    case 3:  //故障等级
                        data = response.getDataInfo().toString();
                        GradeBean listBeans = JSON.parseObject(data, GradeBean.class);
                        List<GradeBean.DataListBean> dataList = listBeans.getDataList();
                        for (int i = 0; i < dataList.size(); i++) {
                            IdBean idBean = new IdBean();
                            int i1 = Integer.parseInt(dataList.get(i).getOid());
                            idBean.setId(i1);
                            idBean.setType(dataList.get(i).getHitchGraContent());
                            mListRawGzdj.add(idBean);
                            mListGzdj.add(dataList.get(i).getHitchGraContent());
                        }
                        break;
                    case 4:  //处理人
                        data = response.getDataInfo().toString();
                        depList = JSON.parseArray(data, DepartmentBean.class);
                        departList.clear();
                        staffList.clear();
                        for (int i = 0; i < depList.size(); i++) {
                            List<DepartmentBean.UserListBean> userList = depList.get(i).getUserList();
                            ArrayList<String> list = new ArrayList<>();
                            for (int j = 0; j < userList.size(); j++) {
                                list.add(userList.get(j).getUserName());
                            }
                            departList.add(depList.get(i).getDepartName());
                            staffList.add(list);
                        }
                        break;
                    case 5:  //故障名称查询
                        data = response.getDataInfo().toString();
                        MmhitchListBean listBean = JSON.parseObject(data, MmhitchListBean.class);
                        List<MmhitchListBean.DataListBean> dataList5 = listBean.getDataList();
                        for (int i = 0; i < dataList5.size(); i++) {
                            IdBean idBean = new IdBean();
                            idBean.setId(dataList5.get(i).getOid());
                            idBean.setType(dataList5.get(i).getHitchContent());
                            mListRawGzmc.add(idBean);
                            mListGzmc.add(dataList5.get(i).getHitchContent());
                        }
                        break;
                    case 6:  //提交
                        Intent intent = new Intent();
                        setResult(2, intent);
                        showToast("新增完成");
                        finish();
                        break;
                    case 7:
                        data = response.getDataInfo().toString();
                        List<SparePartBean> sparePartBeans = JSON.parseArray(data, SparePartBean.class);

                        for (SparePartBean spBean : sparePartBeans) {
                            SpareParBean spareParBean = new SpareParBean();
                            spareParBean.setSpOid(spBean.getOid());
                            spareParBean.setSpName(spBean.getSpName());
                            mListRawBj.add(spareParBean);
                            mListBj.add(spBean.getSpName());
                        }

                       /* for (int i = 0; i < sparePartBeans.size(); i++) {
                            SpareParBean spareParBean = new SpareParBean();
                            spareParBean.setSpOid(sparePartBeans.get(i).getOid());
                            spareParBean.setSpName(sparePartBeans.get(i).getSpName());
                            mListRawBj.add(spareParBean);
                            mListBj.add(sparePartBeans.get(i).getSpName());
                        }*/
                        break;
                }


            } else {
                showToast(response.getMsg());
            }
        }

        @Override
        public void onError(Throwable e, int id) {

        }
    };

    @Override
    public void onClick(View view) {
        int id = view.getId();
        if (id == R.id.ll_gzlb) {  /**选择故障类别*/
            if (ObjectUtils.notEmpty(mListGzlb)) {
                gzlbPicker.setPicker(mListGzlb);
                gzlbPicker.show();
            } else {
                showToast("暂无故障等级");
            }
        } else if (id == R.id.ll_gzmc) {  /**选择故障名称*/
            if ("".equals(gzlbType) || null == gzlbType) {
                showToast("请选择故障类别");
                return;
            }
            if (ObjectUtils.notEmpty(mListGzmc)) {
                gzmcPicker.setPicker(mListGzmc);
                gzmcPicker.show();
            } else {
                showToast(gzlbType + "暂无故障名称，请选择其他故障类别");
            }
        } else if (id == R.id.ll_gzdj) {   /**选择故障等级*/
            if (ObjectUtils.notEmpty(mListGzdj)) {
                gzdjPicker.setPicker(mListGzdj);
                gzdjPicker.show();
            } else {
                showToast("暂无故障等级");
            }
        } else if (id == R.id.ll_wxr) {
            if (ObjectUtils.notEmpty(departList) && ObjectUtils.notEmpty(staffList)) {
                wxrPicker.setPicker(departList, staffList);
                wxrPicker.show();
            } else {
                showToast("暂无维修人");
            }
        } else if (id == R.id.ll_bj) {  /**备件选择*/
            if (ObjectUtils.notEmpty(mListBj)) {
                spPicker.setPicker(mListBj);
                spPicker.show();
            } else {
                showToast("暂无故障等级");
            }
        } else if (id == R.id.tv_repair_confirm) {
            repairConfirm();
        }
    }

    private void repairConfirm() {
        String gzms = mEtGzms.getText().toString();
        String wxfy = mEtWxfy.getText().toString();
        if (wxfy.isEmpty()) {
            wxfy = "0";
        }
        String clff = mEtClff.getText().toString();
        if ("".equals(gzlbType) || null == gzlbType) {
            showToast("请选择故障类别");
            return;
        }
        if (10001 == gzmcID) {
            showToast("请选择故障名称");
            return;
        }
        if (10001 == gzdjID) {
            showToast("请选择故障等级");
            return;
        }
        if (10001 == wxrID) {
            showToast("请选择维修人");
            return;
        }
        tjParams = new HttpParams();

        tjParams.put("userId", userId);  //用户id
        tjParams.put("hitchId", gzmcID + "");  //故障名称 ID
        tjParams.put("hitchGrandId", gzdjID + ""); //故障等级 ID
        tjParams.put("serviceUserId", wxrID + "");  //维修人 ID
        tjParams.put("repearCost", wxfy);  //维修费用

        switch (type) {
            case 0: //更新
                List<SpareParBean> spareBean = mSpAdapter.getSpareBean();
                String s = JSON.toJSONString(spareBean);
                for (int i = 0; i < spareBean.size(); i++) {
                    if ("".equals(spareBean.get(i).getSpAmount())){
                        showToast("请输入第"+i+"条的备件数量");
                        return;
                    }
                }
                LogUtils.e("acasjk+====abhbsabkasnkjbk==="+s);
                tjParams.put("oid", oid);
                tjParams.put("sp", s);
                OkGoUtils.getInstance().post(this, URL.EQ_UP_REPAIR, tjParams, 6, false, callback);  //更新报修
                break;
            case 1: //新增
                tjParams.put("equipId", oid);  //设备编号
                tjParams.put("hitchDetail", gzms);  //故障 描述
                tjParams.put("dealMeth", clff);  //处理方法
                join = Joiner.on(",").join(imagePath);
                LogUtils.e("1ac===========" + join);
                tjParams.put("imagePath", join);
                OkGoUtils.getInstance().post(this, URL.EQ_MAINTENANCE, tjParams, 6, false, callback);  //新增报修
                break;
        }

    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
            View v = getCurrentFocus();
            //当isShouldHideInput(v, ev)为true时，表示的是点击输入框区域，则需要显示键盘，同时显示光标，反之，需要隐藏键盘、光标
            if (ToolUtils.isShouldHideInput(v, ev)) {

                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                if (imm != null) {
                    imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
                    //处理Editext的光标隐藏、显示逻辑
                    mEtGzms.clearFocus();
                    mEtWxfy.clearFocus();
                    mEtClff.clearFocus();
                }
            }
            return super.dispatchTouchEvent(ev);
        }
        // 必不可少，否则所有的组件都不会有TouchEvent了
        if (getWindow().superDispatchTouchEvent(ev)) {
            return true;
        }
        return onTouchEvent(ev);
    }
}




